%{
    #include <stdbool.h>
    #include <string.h>
    #include "IR-struct.h"
    #include "syntax.tab.h"
%}


%%

":"                     { return IR_TOKEN_COLON; }
"FUNCTION"              { return IR_TOKEN_FUNCTION; }
"LABEL"                 { return IR_TOKEN_LABEL; }
"#"                     { return IR_TOKEN_SHARP; }
-?[0-9]+                {
                            char *endptr;
                            int val = strtol(yytext, &endptr, 0);
                            yylval.INT = val;
                            return IR_TOKEN_INT;
                        }
":="                    { return IR_TOKEN_ASSIGN; }
"+"                     { return IR_TOKEN_PLUS; }
"-"                     { return IR_TOKEN_MINUS; }
"*"                     { return IR_TOKEN_STAR; }
"/"                     { return IR_TOKEN_DIV; }
"=="                    { yylval.IR_relop_type = IR_RELOP_EQ;  return IR_TOKEN_RELOP; }
"!="                    { yylval.IR_relop_type = IR_RELOP_NE;  return IR_TOKEN_RELOP; }
">"                     { yylval.IR_relop_type = IR_RELOP_GT;  return IR_TOKEN_RELOP; }
">="                    { yylval.IR_relop_type = IR_RELOP_GE;  return IR_TOKEN_RELOP; }
"<"                     { yylval.IR_relop_type = IR_RELOP_LT;  return IR_TOKEN_RELOP; }
"<="                    { yylval.IR_relop_type = IR_RELOP_LE;  return IR_TOKEN_RELOP; }
"&"                     { return IR_TOKEN_ADDR_OF; }
"IF"                    { return IR_TOKEN_IF; }
"GOTO"                  { return IR_TOKEN_GOTO; }
"RETURN"                { return IR_TOKEN_RETURN; }
"DEC"                   { return IR_TOKEN_DEC; }
"ARG"                   { return IR_TOKEN_ARG; }
"CALL"                  { return IR_TOKEN_CALL; }
"PARAM"                 { return IR_TOKEN_PARAM; }
"READ"                  { return IR_TOKEN_READ; }
"WRITE"                 { return IR_TOKEN_WRITE; }
[a-zA-Z_][a-zA-Z0-9_]*  {
                            yylval.id = strdup(yytext);
                            return IR_TOKEN_ID;
                        }

[ \t]                   /* ignored */
\n+                     { return IR_TOKEN_EOL; }

.	                    { printf("Mysterious token \"%s\".\n", yytext); }

%%

